<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/vue.js"></script>
    <style>
        .nav{
            display: flex;
        }
        .nav span{
            width: 80px;
            height: 40px;
            background-color: #ccc;
            line-height: 40px;
            text-align: center;
            cursor: pointer;
        }
        .active{
            color: white;
            background-color: lightskyblue !important;
        }
        input{
            margin: 5px 0;
        }
        .commentsBox{
            padding: 15px 0;
        }
        .item{
            padding:20px  10px ;
            background-color: #eee;
            width: 400px;
            height: 60px;
            margin-bottom: 5px;
        }
    </style>
</head>
<body>
    <div id="app">
        <div class="nav">
            <span @click="n=1" :class="[n==1?'active':'']" >评论管理</span>
            <span @click="n=2" :class="[n==2?'active':'']">发布评论</span>
        </div>
        <div v-show="n==1" class="commentsBox">
            <div v-if="comments.length == 0">暂无评论</div>
            <div class="item" v-for="(item,index) of comments" :key="index">
                <div>评论人：{{item.nickname}}</div>
                <div>评论时间：{{item.time}}</div>
                <div>评论内容：{{item.content}}</div>
            </div>
        </div>
        <div v-show="n==2">
            <input type="text" v-model="nickname" placeholder="昵称"> <br>
            <input type="text" v-model="content" placeholder="内容"> <br>
            <button @click="addCom">提交评论</button>
        </div>
    </div>
</body>
<script>
    let vm = new Vue({
        el: '#app',
        data() {
            return {
                n:2,
                nickname:'',
                content:'',
                comments:[]
            }
        },
        methods:{
            addCom(){
                this.comments.push({nickname:this.nickname,content:this.content,time:new Date().toLocaleDateString()});
                this.nickname='';
                this.content='';
            }
        }
    })
</script>
</html>